package com.ubs.training.server.service;

import com.ubs.training.prod.server.service.LoggingService;
import com.ubs.training.server.dao.LinkClientDao;
import com.ubs.training.server.dao.model.Client;
import com.ubs.training.server.dao.model.LinkClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: xubuntu
 * Date: 8/22/12
 * Time: 3:54 AM
 * To change this template use File | Settings | File Templates.
 */
@Service
public class LinkClientService {

    @Autowired
    private LinkClientDao linkClientDao;
    @Autowired
    private LoggingService svc;

    public LinkClientDao getLinkClientDao() {
        return linkClientDao;
    }

    public void setLinkClientDao(LinkClientDao linkClientDao) {
        this.linkClientDao = linkClientDao;
    }

    public LoggingService getSvc() {
        return svc;
    }

    public void setSvc(LoggingService svc) {
        this.svc = svc;
    }

    public List<LinkClient> getAll(){
        svc.logEvent(LinkedClientsConstant.getall.toString());
        return  linkClientDao.getAll();
    }

    public LinkClient getByLinkClientId(int id){
        svc.logEvent((LinkedClientsConstant.getById.toString()));
        return linkClientDao.getById(id);
    }


    public Client getByClientID(int i){
        svc.logEvent(LinkedClientsConstant.getById.toString());
        return  linkClientDao.getTargetClient(i);
    }

    public void saveLinkClient(LinkClient l)
    {
        if(l.getId()==0){
            linkClientDao.add(l);
            svc.logEvent(LinkedClientsConstant.add.toString());
        }else
        {
            linkClientDao.update(l);
            svc.logEvent(LinkedClientsConstant.update.toString());

        }
    }
    public void removeLinkCLient(int id){
        svc.logEvent(LinkedClientsConstant.remove.toString());
        linkClientDao.remove(id);
    }


}
